Skip to content

DATAMONGO-2195 - Consider version when removing an entity. #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

christophstrobl
Copy link
Member

@christophstrobl christophstrobl commented Feb 4, 2019

We now consider a potential @Version when removing an entity.

MongoOperations#remove(Object) and MongoOperations#remove(Object, String) now throw an OptimisticLockingFailureException when the object to remove is versioned and the version of the given entity does not match the one within the store. If no document with matching _id can be found the remove operation passes without an error. Same applies to remove operations executed inside an ongoing MongoDB transaction.

MongoRepository now also considers the entities version, following the very same logic as MongoOperations.

To remove an entity without version check use MongoOperations#remove(Query,…) or MongoRepository#deleteById(…

This PR also includes a fix (2nd commit) for DATAMONGO-2196 that should be back ported to 2.1.x and 2.0.x.

…e operations.

We now make sure to apply the WriteConcern correctly when calling deleteOne on MongoCollection.
We now consider a potential @Version when removing an entity.

MongoOperations#remove(Object) and MongoOperations#remove(Object,  String) new throw an OptimisticLockingFailureException when the object to remove is versioned and the version of the given entity does not match the one within the store.
If no document with matching _id can be found the remove operation passes without an error.
MongoRepository now also considers the entities version, following the very same logic as MongoOperations.
To remove an entity without version check use MongoOperations#remove(Query,…) or MongoRepository#deleteById(…

}).flatMap(deleteResult -> {

if (entity != null && entity.hasVersionProperty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please invert the if clauses to use early returns to avoid the heavy nesting.

*/
default Query getRemoveByQuery() {

if (isVersionedEntity()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ternary ? true : false. ;)

mp911de and others added 2 commits February 6, 2019 11:29
…ly in repositories.

OptimisticLockingFailureException is now thrown only when deleting an entity through a repository and no longer when using the Template API.
mp911de pushed a commit that referenced this pull request Feb 7, 2019
…e operations.

We now make sure to apply the WriteConcern correctly when calling deleteOne on MongoCollection.

Original pull request: #641.
mp911de pushed a commit that referenced this pull request Feb 7, 2019
We now consider a potential @Version when removing an entity.

MongoOperations#remove(Object) and MongoOperations#remove(Object, String) include the version of the object to remove if the entity is versioned. Opposed to save(Object), remove(Object) does not throw OptimisticLockingFailureException if a versioned entity could not be removed. This behavior is subject to be changed in a future release. Throwing OptimisticLockingFailureException on failed delete on Template API level was not introduced to not break existing application code.

MongoRepository now also considers the entities version, following the very same logic as MongoOperations.
To remove an entity without version check use MongoOperations#remove(Query,…) or MongoRepository#deleteById(…).

Original pull request: #641.
mp911de added a commit that referenced this pull request Feb 7, 2019
…ly in repositories.

OptimisticLockingFailureException is now thrown only when deleting an entity through a repository and no longer when using the Template API.

Original pull request: #641.
mp911de pushed a commit that referenced this pull request Feb 7, 2019
mp911de pushed a commit that referenced this pull request Feb 7, 2019
…e operations.

We now make sure to apply the WriteConcern correctly when calling deleteOne on MongoCollection.

Original pull request: #641.
@mp911de
Copy link
Member

mp911de commented Feb 7, 2019

That's merged, polished and partially backported now.

@mp911de mp911de closed this Feb 7, 2019
@mp911de mp911de deleted the issue/DATAMONGO-2195 branch February 7, 2019 14:22
mp911de added a commit that referenced this pull request Feb 12, 2019
Fix stubbing in test that sneaked in through a back port not considering the change which method was used for entity removal.

Original pull request: #641.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants